package org.example.myleet.p566;

public class Solution {
    /**
     * 1 ms
     * 总数不同的话就不能转换，转换时遍历数组并通过不断更新新坐标填充新数组
     */
    public int[][] matrixReshape(int[][] nums, int r, int c) {
        int r0 = nums.length;
        int c0 = nums[0].length;
        if (r0 * c0 != r * c) {
            return nums;
        }
        int[][] result = new int[r][c];
        int m = 0, n = 0;
        for (int i=0; i<r0; i++) {
            for (int j=0; j<c0; j++) {
                result[m][n++] = nums[i][j];
                if (n == c) {
                    n = 0;
                    ++m;
                }
            }
        }
        return result;
    }
}
